package com.example.service;


import com.example.entity.Book;
import com.example.entity.SeatRecord;
import com.example.exception.CustomerException;
import com.example.mapper.SeatRecordMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SeatRecordService {
    @Autowired
    private BookService bookService;
    @Autowired
    private SeatRecordMapper seatRecordMapper;
    public List<SeatRecord> selectAll(SeatRecord seatRecord){
        return seatRecordMapper.selectAll(seatRecord);
    }

    public PageInfo<SeatRecord> selectPage(Integer pageNum, Integer pageSize,SeatRecord seatRecord) {
        PageHelper.startPage(pageNum,pageSize);
        List<SeatRecord> list = seatRecordMapper.selectAll(seatRecord);
        return PageInfo.of(list);

    }

    public void add(SeatRecord seatRecord) {
        seatRecordMapper.insert(seatRecord);
    }

    public void update(SeatRecord seatRecord) {
        seatRecordMapper.updateById(seatRecord);
    }

    public void deleteById(Integer id) {
//        Book book = bookService.selectBySeatRecordId(id);
//        if (book==null){
//            seatRecordMapper.deleteById(id);
//        }else {
//            throw new CustomerException("该分类下存在书籍，无法删除");
//        }
        seatRecordMapper.deleteById(id);
    }


    @Transactional
    public void deleteBatch(List<Integer> idList) {
        for (Integer id : idList) {
//            seatRecordMapper.deleteById(id);
            this.deleteById(id);
        }
    }

//    public void cancelById(Integer id) {
//        seatRecordMapper.cancelById(id);
//    }
}
